package reference;

import java.lang.ref.ReferenceQueue;
import java.lang.ref.SoftReference;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zhangxin
 * @date 2020/8/28
 */
public class SoftReferenceTest {

    public static void main(String[] args) {
        List<TestObject> list = new ArrayList<>();
        TestObject object = new TestObject();
        list.add(object);

        ReferenceQueue<Object> objectReferenceQueue = new ReferenceQueue<>();
        SoftReference softReference = new SoftReference<>(object, objectReferenceQueue);


        object = null;
/*        System.gc();
        System.runFinalization();

        System.gc();
        System.runFinalization();*/
        byte[] a = new byte[1024 * 1024 * 10];

        byte[] v = new byte[1024 * 1024 * 10];

        byte[] d = new byte[1024 * 1024 * 10];

        for (int i = 0; i < 20; i++) {
            byte[] a1 = new byte[1024 * 1024 * 10];
            // System.out.println(a.length);
        }
        System.out.println("softReference get : " + softReference.get());
        System.out.println("objectReferenceQueue: " + objectReferenceQueue.poll());
    }
}
